/*
 * Copyright (C) 2011 Dirk Weißenborn, dirk.weissenborn@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.weissenborn.colabtex.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.weissenborn.colabtex.client.places.AccountManagement;
import com.weissenborn.colabtex.client.places.GroupCreation;
import com.weissenborn.colabtex.client.places.GroupManagement;
import com.google.gwt.user.client.ui.DockLayoutPanel;

/**
 * The Class HeaderViewImpl.
 */
public class HeaderViewImpl extends Composite implements HeaderView {

	/**
	 * The Interface Binder.
	 */
	interface Binder extends UiBinder<Widget, HeaderViewImpl> {
	}
	
	/** The Constant binder. */
	private static final Binder binder = GWT.create(Binder.class);
	
	/** The edit group btn. */
	@UiField Button editGroupBtn;
	
	/** The leave group btn. */
	@UiField Button leaveGroupBtn;
	
	/** The logout btn. */
	@UiField Button logoutBtn;
	
	/** The header panel. */
	@UiField DockLayoutPanel headerPanel;
	
	/** The account managment btn. */
	@UiField Button accountManagmentBtn;
	
	/** The listener. */
	private Presenter listener;

	/**
	 * Instantiates a new header view impl.
	 */
	public HeaderViewImpl() {
		initWidget(binder.createAndBindUi(this));
	}

	/* (non-Javadoc)
	 * @see com.weissenborn.colabtex.client.view.HeaderView#setPresenter(com.weissenborn.colabtex.client.view.HeaderView.Presenter)
	 */
	public void setPresenter(Presenter listener) {
		this.listener = listener;
	}
	
	/**
	 * On create group btn click.
	 *
	 * @param event the event
	 */
	@UiHandler("createGroupBtn")
	void onCreateGroupBtnClick(ClickEvent event) {
		listener.goTo(new GroupCreation());
	}
	
	/**
	 * On edit group btn click.
	 *
	 * @param event the event
	 */
	@UiHandler("editGroupBtn")
	void onEditGroupBtnClick(ClickEvent event) {
		listener.goTo(new GroupManagement());
	}
	
	/**
	 * On logout btn click.
	 *
	 * @param event the event
	 */
	@UiHandler("logoutBtn")
	void onLogoutBtnClick(ClickEvent event) {
		listener.logout();
	}
	
	/**
	 * On leave group btn click.
	 *
	 * @param event the event
	 */
	@UiHandler("leaveGroupBtn")
	void onLeaveGroupBtnClick(ClickEvent event) {
		listener.leaveCurrentGroup();
	}
	
	/**
	 * On account managment btn click.
	 *
	 * @param event the event
	 */
	@UiHandler("accountManagmentBtn")
	void onAccountManagmentBtnClick(ClickEvent event) {
		listener.goTo(new AccountManagement());
	}
}
